@extends('layout.admin.master')
@section('content')
    <div class="card">
        <div class="card-body">
            <ul class="nav nav-tabs nav-tabs-sm">
                <li class="nav-item">
                    <a href="{{route('news.lists')}}" class="nav-link ">
                        新闻列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{route('news.news.create')}}" class="nav-link active">
                        添加新闻
                    </a>
                </li>
            </ul>
        </div>
    </div>
    <form action="{{route('news.news.store')}}" method="post" id="app">
        @csrf
        <div class="card">
            <div class="card-body">
                <div class="form-group">
                    <label for="">新闻标题</label>
                    <input type="text" name="title" id="" class="form-control" placeholder="" aria-describedby="helpId">
                </div>
                <div class="form-group">
                    <label for="">新闻简介</label>
                    <input type="text" name="brief" id="" class="form-control" placeholder="" aria-describedby="helpId">
                </div>

                <div class="form-group">
                    <label for="">选择新闻分类</label>
                    <select name="classify_id" id="" class="form-control">
                        <option value="0">顶级分类</option>
                        @foreach($classify as $value)
                                <option value="{{$value['id']}}">{{$value['_name']}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group">
                    <label for="">新闻缩略图</label>
                    <input class="form-control"  readonly="" value="" name="icon">
                    <div class="input-group-append mt-3" >
                        <button onclick="upImagePc()" class="btn btn-secondary" type="button">单图上传</button>
                    </div>
                    <div style="display: inline-block;position: relative;">
                        <img src="" class="img-responsive img-thumbnail" width="150">
                    </div>
                </div>
                <div class="form-group">
                    <label for="">新闻内容</label>
                    <div id="editormd"><textarea name="content" style="display:none;"></textarea></div>
                </div>

            </div>
        </div>
        <div class="card-footer text-muted">
            <button type="submit" class="btn btn-primary">保存数据</button>
        </div>
    </form>
@endsection
@push('js')
    <script>
        require(['hdjs'], function (hdjs) {
            hdjs.editormd("editormd", {
                width: '100%',
                height: 300,
                toolbarIcons : function() {
                    return [
                        "bold", "del", "italic", "quote","|",
                        "list-ul", "list-ol", "hr", "|",
                        "link", "hdimage", "code-block", "|",
                        "watch", "preview", "fullscreen"
                    ]
                },
                //editor.md库位置
                path: "{{asset('org/hdjs')}}/package/editor.md/lib/"
            });
        });
    </script>
    @endpush
@push('js')
    <script>
        require(['hdjs','bootstrap']);
        function upImagePc() {
            require(['hdjs'], function (hdjs) {
                var options = {
                    multiple: false,//是否允许多图上传
                    data: {name: '后盾人', year: 2099},
                };
                hdjs.image(function (images) {
                    //上传成功的图片，数组类型
                    $("[name='icon']").val(images[0]);
                    // $(".img-thumbnail").attr('src', images[0]);
                }, options)
            });
        }
    </script>
    @endpush